//
//  ZGLAgainstCell.m
//  ZeegingLottery
//
//  Created by 蒂埃里 on 2018/4/13.
//  Copyright © 2018年 蒂埃里. All rights reserved.
//

#import "ZGLAgainstCell.h"

#import "ZGLOddsTabView.h"

@interface ZGLAgainstCell ()

@property (strong, nonatomic)UILabel *homeTeamNameLabel;
@property (strong, nonatomic)UILabel *awayTeamNameLabel;
@property (strong, nonatomic)UILabel *homeTagLable;
@property (strong, nonatomic)UILabel *awayTagLable;
@property (strong, nonatomic)UILabel *VSLabel;
@property (strong, nonatomic)UILabel *matchkeycnLabel;       //周一001
@property (strong, nonatomic)UILabel *leaguenameabbrLable;   //联赛名称
@property (strong, nonatomic)UILabel *endingTimeLabel;       //截止时间
@property (strong, nonatomic)ZGLOddsTabView *oddsTabView;

@property (strong, nonatomic)NSMutableArray *selectionArray;   //选中的赔率



@end

@implementation ZGLAgainstCell

+ (instancetype)againstCellWithTableView:(YUFoldingTableView *)tableView
{
    static NSString *ZGLAgainstCellID = @"ZGLAgainstCell";
    ZGLAgainstCell *cell = [tableView dequeueReusableCellWithIdentifier:ZGLAgainstCellID];
    if (cell == nil) {
        cell = [[ZGLAgainstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ZGLAgainstCellID];
    }
    
    return cell;
}
+ (instancetype)againstCellWithTableView:(YUFoldingTableView *)tableView indexPath:(NSIndexPath *)indexPath
{
    NSString *ZGLAgainstCellID = [NSString stringWithFormat:@"ZGLAgainstCell%ld%ld",(long)indexPath.section,(long)indexPath.row];
    
    ZGLAgainstCell *cell = [tableView dequeueReusableCellWithIdentifier:ZGLAgainstCellID];
//    NSIndexPath *Index = [tableView indexPathForCell:cell];
    if (cell == nil) {
        cell = [[ZGLAgainstCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ZGLAgainstCellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
 
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = ViewBackgroundColor;

        [self.contentView addSubview:self.oddsTabView];
        [self.contentView addSubview:self.leaguenameabbrLable];
        [self.contentView addSubview:self.matchkeycnLabel];
        [self.contentView addSubview:self.endingTimeLabel];
        [self.contentView addSubview:self.VSLabel];
        [self.contentView addSubview:self.homeTeamNameLabel];
        [self.contentView addSubview:self.awayTeamNameLabel];
        [self.contentView addSubview:self.homeTagLable];
        [self.contentView addSubview:self.awayTagLable];
        
        
        [HKUIUtils addLineInView:self.contentView color:BorderColor top:NO leftMargin:0 rightMargin:0];
        
        [self setupUI];
    }
    return self;
}

- (void)setModel:(ZGLAgainstModel *)model
{
    if (model) {
        _model = model;
        self.matchkeycnLabel.text = model.matchkeycn;
        self.leaguenameabbrLable.text = model.leaguenameabbr;
        NSString *closeTimeStr = [model.closetime substringWithRange:NSMakeRange(11, 5)];
        self.endingTimeLabel.text = [NSString stringWithFormat:@"%@ 截止",closeTimeStr];
        self.homeTeamNameLabel.text = model.home.teamname;
        self.awayTeamNameLabel.text = model.away.teamname;
        self.oddsTabView.hadModel = model.had;
        self.oddsTabView.hhadModel = model.hhad;
        self.oddsTabView.Againstmodel = model;
        if (model.stateArray.count>0) {
            
            self.oddsTabView.selectStateArray = model.stateArray;
        }
    }

}


#pragma mark - getter

- (NSMutableArray *)selectionArray
{
    if (!_selectionArray) {
        _selectionArray = [NSMutableArray array];
    }
    return _selectionArray;
}


- (ZGLOddsTabView *)oddsTabView
{
    if (!_oddsTabView) {
        _oddsTabView = [[ZGLOddsTabView alloc]initWithFrame:CGRectMake(0, 0, sBtnW, sBtnH)];
        WS(weakself)
//        _oddsTabView.currentIndexPath = _currentIndex;
        _oddsTabView.matchArrBlock = ^(NSInteger Num) {
            
            if (weakSelf.modelsBlock) {
                weakSelf.modelsBlock(Num);
            }
            
        };
    }
    return _oddsTabView;
}

- (UILabel *)leaguenameabbrLable
{
    if (!_leaguenameabbrLable) {
        _leaguenameabbrLable = [[UILabel alloc]init];
        _leaguenameabbrLable.font = [UIFont fontWithName:@"Arial" size:btnFontSize];
        _leaguenameabbrLable.textAlignment = 1;
        _leaguenameabbrLable.textColor = detailTextColor;
        
    }
    return _leaguenameabbrLable;
}

- (UILabel *)matchkeycnLabel
{
    if (!_matchkeycnLabel) {
        _matchkeycnLabel = [[UILabel alloc]init];
        _matchkeycnLabel.font = [UIFont fontWithName:@"Arial" size:btnFontSize];
        _matchkeycnLabel.textAlignment = 1;
        _matchkeycnLabel.textColor = detailTextColor;
    }
    return _matchkeycnLabel;
}

- (UILabel *)endingTimeLabel
{
    if (!_endingTimeLabel) {
        _endingTimeLabel = [[UILabel alloc]init];
        _endingTimeLabel.font = [UIFont fontWithName:@"Arial" size:btnFontSize];
        _endingTimeLabel.textAlignment = 1;
        _endingTimeLabel.textColor = detailTextColor;
    }
    return _endingTimeLabel;
}

- (UILabel *)VSLabel
{
    if (!_VSLabel) {
        _VSLabel = [[UILabel alloc]init];
        _VSLabel.textAlignment = 1;
        _VSLabel.textColor = detailTextColor;
        _VSLabel.font = [UIFont systemFontOfSize:14];
        _VSLabel.text = @"VS";
        
    }
    return _VSLabel;
}

-(UILabel *)homeTeamNameLabel
{
    if (!_homeTeamNameLabel) {
        _homeTeamNameLabel = [[UILabel alloc]init];
        _homeTeamNameLabel.textAlignment = 1;
        _homeTeamNameLabel.textColor = mainTextColor;
        _homeTeamNameLabel.font = [UIFont systemFontOfSize:13];
    }
    
    return _homeTeamNameLabel;
}

-(UILabel *)awayTeamNameLabel
{
    if (!_awayTeamNameLabel) {
        _awayTeamNameLabel = [[UILabel alloc]init];
        _awayTeamNameLabel.textAlignment = 1;
        _awayTeamNameLabel.textColor = mainTextColor;
        _awayTeamNameLabel.font = [UIFont systemFontOfSize:13];
    }
    return _awayTeamNameLabel;
}

- (UILabel *)homeTagLable
{
    if (!_homeTagLable) {
        _homeTagLable = [[UILabel alloc]init];
        _homeTagLable.font = [UIFont systemFontOfSize:labelFontSize];
        _homeTagLable.textAlignment = 1;
        _homeTagLable.textColor = detailTextColor;
        _homeTagLable.text = @"(主)";
    }
    return _homeTagLable;
}

-(UILabel *)awayTagLable
{
    if (!_awayTagLable) {
        _awayTagLable = [[UILabel alloc]init];
        _awayTagLable.font = [UIFont systemFontOfSize:labelFontSize];
        _awayTagLable.textAlignment = 1;
        _awayTagLable.textColor = detailTextColor;
    }
    return _awayTagLable;
}



- (void)setupUI
{
    CGFloat margin;
    if (IS_IPHONE_4and5) {
        margin = 10;
    }else{
        margin = 15;
    }
    
    //
    [_oddsTabView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.right.equalTo(self.contentView).offset(-10);
        make.bottom.equalTo(self.contentView).offset(-margin);
        make.height.equalTo(@(sBtnH));
//        make.width.equalTo(@(sBtnW));
        make.left.equalTo(_leaguenameabbrLable.mas_right);
    }];
    
    [_leaguenameabbrLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self.contentView).offset(margin);
        make.centerY.equalTo(_oddsTabView.mas_centerY);
//        make.right.equalTo(_oddsTabView.mas_left);
        make.width.equalTo(@(80));
    }];
    _leaguenameabbrLable.text = @"英超";
    
    [_matchkeycnLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_leaguenameabbrLable);
        make.right.equalTo(_leaguenameabbrLable);
        make.bottom.equalTo(_leaguenameabbrLable.mas_top).offset(-5);
    }];
    _matchkeycnLabel.text = @"周日 001";
    
    [_endingTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_leaguenameabbrLable);
        make.right.equalTo(_leaguenameabbrLable);
        make.top.equalTo(_leaguenameabbrLable.mas_bottom).offset(5);
    }];
    _endingTimeLabel.text = @"23:59 截止";
    
    [_VSLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(_oddsTabView.mas_centerX);
        make.width.mas_equalTo(25);
        make.top.equalTo(self.contentView);
        make.bottom.equalTo(_oddsTabView.mas_top);
    }];
    
    [_homeTeamNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(_VSLabel);
        make.right.equalTo(_VSLabel.mas_left);
    }];
    _homeTeamNameLabel.text = @"巴塞罗那";
    
    [_awayTeamNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.equalTo(_VSLabel);
        make.left.equalTo(_VSLabel.mas_right);
    }];
    _awayTeamNameLabel.text = @"皇家马德里";
    
    [_homeTagLable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_homeTeamNameLabel.mas_left).offset(-5);
        make.bottom.equalTo(_homeTeamNameLabel);
    }];
//    _homeTagLable.text = @"";
    
//    [_awayTagLable mas_makeConstraints:^(MASConstraintMaker *make) {
//
//        make.left.equalTo(_awayTeamNameLabel.mas_right);
//        make.bottom.equalTo(_awayTeamNameLabel);
//    }];
//    _awayTagLable.text = @"[9]";
}


@end
